<!-- <button (click) = "getDatabases()" >获取所有数据库</button>
<button (click) = "connectServer()">链接数据库服务器</button> -->
<!-- <button nz-button (click)="printEval()"></button> -->
<div nz-row>
    <div nz-col nzSpan="6">
    <div>
        <div> <!-- 左侧树形结构 -->
            <div nz-row nzType="flex" nzJustify="space-around" nzAlign="middle">
                <div nz-col nzSpan="14" class="treeSearchInput">
                    <nz-input-group [nzSuffix]="suffixIcon">
                        <input #searchInput type="text" nz-input placeholder="Search" [(ngModel)]="searchValue" 
                            (ngModelChange)="searchChange($event)"/>
                    </nz-input-group>
                    <ng-template #suffixIcon>
                        <i nz-icon nzType="search"></i>
                    </ng-template>
                </div>

                <div nz-col nzSpan="2" class="treeLinker">
                    <a nz-tooltip nzTooltipTitle="更新本地数据" (click)="refreshLocalData()"><i nz-icon nzType="sync" nzTheme="outline"></i></a>
                </div>

                <div nz-col nzSpan="2" class="treeLinker">
                    <a nz-tooltip nzTooltipTitle="连接服务器" (click)="connectServer()"><i nz-icon nzType="link" nzTheme="outline"></i></a>
                </div>

                <div nz-col nzSpan="3" class="treeMatchSwitcher">
                    <nz-switch nzSize="small" [(ngModel)]="hideUnMatched" nz-tooltip nzTooltipTitle="隐藏非匹配" (click)="clickSwitcher()"></nz-switch>
                </div>
            </div>


            <div nz-col nzSpan="24" class="treeContainer">
            <nz-tree #tree [nzData]="treeData" [nzSearchValue]="delayedSearchValue" (nzClick)="treeClick($event)" 
                [nzHideUnMatched]="hideUnMatched"
                (nzExpandChange)="treeNodeExpand($event)"
                (nzSearchValueChange)="searchValueChange($event)">
            </nz-tree>
            </div>
        </div>
    </div>
    </div>

    <!-- 右侧编辑区域 -->
    <div nz-col nzSpan="18">
        <div nz-col nzSpan="24" class="editorContainer">

            <div nz-row nzType="flex" nzJustify="start">
                <div nz-col nzSpan="24" class="toolBarContainer" style="padding-left: 10px;">
                    <nz-button-group>
                        <button nz-button (click)="createAngularModel()">生成Angular Model</button>
                        
                        <button nz-button
                            nz-popconfirm
                            nzPopconfirmTitle="使用字段原始名称作为属性名？"
                            nzOkText="是"
                            nzCancelText="否"
                            (nzOnConfirm)="createMybatisSaveBatch(true)"
                            (nzOnCancel)="createMybatisSaveBatch(false)">
                            生成Mybatis批量插入</button>

                        <button nz-button (click)="createMybatisSaveOne()"
                            nz-popover nzPopoverTitle="设置模型包名路径："
                            [(nzVisible)]="popOverVisible_createMybatisSaveOne"
                            (nzVisibleChange)="change_createMybatisSaveOne($event)"
                            nzPopoverTrigger="click"
                            [nzPopoverContent]="contentTemplate_createMybatisSaveOne">
                            生成Mybatis单行新增/修改</button>

                        <button nz-button (click)="createMybatisSelectAll()">生成Mybatis - SelectAll</button>

                        <button nz-button (click)="createSpringDao()"
                        nz-popover nzPopoverTitle="设置模型类名称："
                        [(nzVisible)]="popOverVisible_createSpringDao"
                        nzPopoverTrigger="click"
                        [nzPopoverContent]="contentTemplate_createSpringDao">
                        生成Spring DAO 自定义三剑客</button>


                        <button nz-button (click)="createSpringController()"
                        nz-popover nzPopoverTitle="设置模型类名称："
                        [(nzVisible)]="popOverVisible_createSpringController"
                        nzPopoverTrigger="click"
                        [nzPopoverContent]="contentTemplate_createSpringController">
                        生成Spring Controller</button>

                        <button nz-button (click)="createAngularService()">生成AngularService</button>
                        <button nz-button (click)="createFieldString()">生成字段字符串</button>
                        <button nz-button (click)="createSingleTemplate()">单表模板代码</button>
                        <button nz-button (click)="visible_SingleControllerForm = !visible_SingleControllerForm">单表控制器代码</button>
                    </nz-button-group>

                    <ng-template #contentTemplate_createSpringController>
                        <div nz-row nzType="flex" nzJustify="space-between" nzAlign="middle"
                            style="width:400px;">
                            <div nz-col nzSpan="20">
                                <input type="text" nz-input [(ngModel)]="modelName_createSpringController"/>
                            </div>

                            <div nz-col nzSpan="2">
                                <a (click)="createSpringControllerGo()">确定</a>
                            </div>
                        </div>
                    </ng-template>


                    <ng-template #contentTemplate_createSpringDao>
                        <div nz-row nzType="flex" nzJustify="space-between" nzAlign="middle"
                            style="width:400px;">
                            <div nz-col nzSpan="20">
                                <input type="text" nz-input [(ngModel)]="modelName_createSpringDao"/>
                            </div>

                            <div nz-col nzSpan="2">
                                <a (click)="createSpringDaoGo()">确定</a>
                            </div>
                        </div>
                    </ng-template>

                    <!-- 生成当行保存+修改 -->
                    <ng-template #contentTemplate_createMybatisSaveOne>
                        <!-- input -->
                        <div nz-row nzType="flex" nzJustify="space-between" nzAlign="middle"
                            style="width:400px;">
                            <div nz-col nzSpan="20">
                                <input type="text" nz-input [(ngModel)]="packagePath_createMybatisSaveOne"/>
                            </div>
                        </div>

                        <!-- 开关 + 按钮 -->
                        <div nz-row nzType="flex" nzJustify="space-between" nzAlign="middle">
                            <div nz-col nzSpan="12">
                                去下划线首字母大写：<nz-switch [(ngModel)]="upperAttribute" nzCheckedChildren="开" nzUnCheckedChildren="关"></nz-switch>
                            </div>
                            <div nz-col nzSpan="4" style="padding: 10px;">
                                <a (click)="save_packagePath_createMybatisSaveOne()">确定</a>
                            </div>
                        </div>
                    </ng-template>

                </div>
            

                <!-- 显示连接到的远程服务器的参数 -->
                <div nz-row nzType="flex" nzJustify="space-around" nzAlign="middle" style="padding: 10px;">
                    <div nz-col nzSpan="24">
                        服务器：{{dbConfig?.server}} - {{dbConfig?.port}} - {{dbConfig?.dbUserName}}
                    </div>
                </div>

                <!-- 显示代码的区域 -->
                <div nz-col nzSpan="24" class="codeZone" style="padding: 10px;">
                    <textarea rows=18 nz-input [(ngModel)]="angularModel"></textarea>
                </div>
            </div>
        </div>
    </div>
</div>


<!-- 设置数据库链接的抽屉 -->
<nz-drawer [nzWidth]="313"
    [nzClosable]="true"
    [nzVisible]="drawerVisible"
    nzPlacement="right"
    nzTitle="数据库链接设置"
    (nzOnClose)="close()"
>

<form nz-form [formGroup]="validateForm" (ngSubmit)="submitForm()">
    <nz-form-item>
        <nz-form-label [nzSm]="6" [nzXs]="24" nzRequired nzFor="server">服务器</nz-form-label>
        <nz-form-control [nzSm]="14" [nzXs]="24" nzErrorTip="必填项">
        <input nz-input formControlName="server" id="server" />
        </nz-form-control>
    </nz-form-item>

    <nz-form-item>
        <nz-form-label [nzSm]="6" [nzXs]="24" nzRequired nzFor="port">端口号</nz-form-label>
        <nz-form-control [nzSm]="14" [nzXs]="24" nzErrorTip="必填项">
            <input nz-input formControlName="port" id="port" />
        </nz-form-control>
    </nz-form-item>

    <nz-form-item>
        <nz-form-label [nzSm]="6" [nzXs]="24" nzRequired nzFor="userName">用户名</nz-form-label>
        <nz-form-control [nzSm]="14" [nzXs]="24" nzErrorTip="必填项">
            <input nz-input formControlName="userName" id="userName" />
        </nz-form-control>
    </nz-form-item>

    <nz-form-item>
        <nz-form-label [nzSm]="6" [nzXs]="24" nzFor="password" nzRequired>密码</nz-form-label>
        <nz-form-control [nzSm]="14" [nzXs]="24" nzErrorTip="必填项">
        <input nz-input type="password" id="password" formControlName="password"/>
        </nz-form-control>
    </nz-form-item>

    
    <nz-form-item nz-row>
        <nz-form-control [nzSpan]="6" [nzOffset]="6">
            <button nz-button nzType="primary">连接</button>
        </nz-form-control>

        <!-- <nz-form-control [nzSpan]="6" [nzOffset]="3">
            <button nz-button nzType="default" (click)="closeDrawer($event)">关闭</button>
        </nz-form-control> -->
    </nz-form-item>
</form>

</nz-drawer>

<!-- 生成单表控制器代码需要的参数：modelName,detailService -->
<nz-drawer [nzWidth]="313"
    [nzClosable]="true"
    [nzVisible]="visible_SingleControllerForm"
    nzPlacement="right"
    nzTitle="代表控制器需要的参数"
    (nzOnClose)="close()"
>
    <form nz-form [nzLayout]="'horizontal'" [formGroup]="singleControllerForm">

        <nz-form-item>
            <nz-form-label [nzSm]="8" [nzXs]="24" nzRequired nzFor="server">表名称</nz-form-label>
            <nz-form-control [nzSm]="14" [nzXs]="24" nzErrorTip="必填项">
            <input nz-input formControlName="tableName" name="tableName" id="tableName" />
            </nz-form-control>
        </nz-form-item>


        <nz-form-item>
            <nz-form-label [nzSm]="8" [nzXs]="24" nzRequired nzFor="server">模型类名</nz-form-label>
            <nz-form-control [nzSm]="14" [nzXs]="24" nzErrorTip="必填项">
            <input nz-input formControlName="modelName" name="modelName" id="modelName" />
            </nz-form-control>
        </nz-form-item>

        <nz-form-item>
            <nz-form-label [nzSm]="8" [nzXs]="24" nzRequired nzFor="server">服务名</nz-form-label>
            <nz-form-control [nzSm]="14" [nzXs]="24" nzErrorTip="必填项">
            <input nz-input formControlName="detailService" name="detailService" id="detailService" />
            </nz-form-control>
        </nz-form-item>
    </form>


    <div class="footer" nz-row nzType="flex" nzJustify="space-between" nzAlign="middle">
        <div nz-col nzSpan="20" nzOffset="4">
            <button type="button" (click)="cancelDrawerEdit()" class="ant-btn" style="margin-right: 8px;"><span>取消</span></button>
            <button type="button" (click)="saveDrawer_SingleControllerParam()" class="ant-btn ant-btn-primary"><span>保存</span></button>
        </div>
    </div>
</nz-drawer>